#include "bsp_config.h"

/****************************************************这里主要是和上层通讯相关的东西********************************************************/
char cmd_buf[128]; //  存储接收到的字符串  mqtt和ble都会使用

/**************************************这里面是MQTT接收处理函数********************************************/
cJSON *cJSON_Data = NULL; //
MQTT_PUB_QUEUE_ENUM_Typedef mqtt_pub_queue_enum;
MQTT_PUB_QUEUE_ENUM_Typedef *pMQTT_PUB_QUEUE_ENUM; //生崽

/**
  * @brief  将字符串中连续的数字串转换成数字
  * @param  p 指向待钻换的数字串
  * @retval 转换完成的数字
  */
static int skip_atoi(const char *s)
{
  register int i = 0;
  while (((unsigned)((*s) - '0') < 10))
  {
    i = i * 10 + *(s++) - '0';
  }
  return i;
}

// int tm_sec;			/* Seconds.	[0-60] (1 leap second) */
// int tm_min;			/* Minutes.	[0-59] */
// int tm_hour;			/* Hours.	[0-23] */
// int tm_mday;			/* Day.		[1-31] */
// int tm_mon;			/* Month.	[0-11] */
// int tm_year;			/* Year	- 1900.  */

/**
  * @brief 对含有时间的字符串进行提取,然后设置RTC时间 
  * @param  p 指向待钻换的数字串
  * @retval 无
  */
static void MQTT_RTC_Set(const char *s)
{
  static struct timeval t_v;
  static struct tm sett__time;
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    sett__time.tm_year = skip_atoi(s) + 100;  //取年
    sett__time.tm_mon = skip_atoi(s + 3) - 1; //取月
    sett__time.tm_mday = skip_atoi(s + 6);    //取天
    sett__time.tm_hour = skip_atoi(s + 9);    //取时
    sett__time.tm_min = skip_atoi(s + 12);    //取分
    sett__time.tm_sec = skip_atoi(s + 15);    //取秒

    t_v.tv_sec = mktime(&sett__time);
    t_v.tv_usec = 0;

    sntp_sync_time(&t_v);

    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
}

/**
  * @brief  根据特定的字符串,设置当前的语言
  * @param  p 指向待钻换的数字串
  * @retval 无
  */
static void MQTT_Language_Set(const char *s)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
}

/**
  * @brief  设置驱蚊出厂设置参数
  * @param  p:指向接收到的字符串
  * @retval 无
  */
static void MQTT_Repel_factory_sett_set(const char *p)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.FactorySetting.factory_sett_data.InitRepelTime = skip_atoi(p);
    ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time = skip_atoi(p + 4);
    ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time = skip_atoi(p + 8);
    ConfigParam.FactorySetting.factory_sett_data.maternal_open_time = skip_atoi(p + 12);
    ConfigParam.FactorySetting.factory_sett_data.maternal_close_time = skip_atoi(p + 16);
    ConfigParam.FactorySetting.factory_sett_data.normal_open_time = skip_atoi(p + 20);
    ConfigParam.FactorySetting.factory_sett_data.normal_close_time = skip_atoi(p + 24);
    ConfigParam.FactorySetting.factory_sett_data.area10m2_factory = skip_atoi(p + 28);
    ConfigParam.FactorySetting.factory_sett_data.area20m2_factory = skip_atoi(p + 32);
    ConfigParam.FactorySetting.factory_sett_data.area30m2_factory = skip_atoi(p + 36);
    // ConfigParam.FactorySetting.repel_ion_delta = skip_atoi(p + 40);
    write_config_param(&ConfigParam.FactorySetting.factory_sett_data.evacuation_times, ConfigParam.FactorySetting.pC, ConfigParam.FactorySetting.length);

    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
}

/**
  * @brief  设置灭蚊出厂设置参数
  * @param  p:指向接收到的字符串
  * @retval 无
  */
static void MQTT_Fumigate_factory_sett_set(const char *p)
{
  float dat1 = 0;
  float dat2 = 0;

  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.FactorySetting.factory_sett_data.evacuation_times = skip_atoi(p);
    if ((uint16_t)ConfigParam.PID_Param.pid_param_data.SetPoint != skip_atoi(p + 4))
    {
      ConfigParam.PID_Param.pid_param_data.SetPoint = skip_atoi(p + 4);
      ConfigParam.PID_Param.pid_param_data.Self_Tuning_Flag = 1; //进入PID整定阶段
      write_config_param(&ConfigParam.PID_Param.pid_param_data.SetPoint, ConfigParam.PID_Param.pC, ConfigParam.PID_Param.length);
    }
    dat1 = skip_atoi(p + 8);  //整数部分
    dat2 = skip_atoi(p + 11); //小数部分
    dat1 = dat1 * 10 + dat2;
    dat1 = dat1 / 10;
    ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 = dat1; //房高是小数
    ConfigParam.FactorySetting.factory_sett_data.fumigate_time = skip_atoi(p + 13);
    write_config_param(&ConfigParam.FactorySetting.factory_sett_data.evacuation_times, ConfigParam.FactorySetting.pC, ConfigParam.FactorySetting.length);

    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
}

/**
  * @brief  设置灭蚊设置参数    上面是出厂设置
  * @param  p:指向接收到的字符串
  * @retval 无
  */
static void MQTT_Fumigate_sett_set(const char *p)
{
  float dat1 = 0;
  float dat2 = 0;

  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    if (strstr(p, "MODE_FUMIGATE_ENCHANCE"))
    {
      MosFumigateEnchanceFunction(); //这种东东得由专门的函数来完成

      dat1 = skip_atoi(strstr(p, "MODE_FUMIGATE_ENCHANCE/") + strlen("MODE_FUMIGATE_ENCHANCE/"));
      dat2 = skip_atoi(strstr(p, "MODE_FUMIGATE_ENCHANCE/") + strlen("MODE_FUMIGATE_ENCHANCE/___"));
      dat1 = dat1 * 10 + dat2;
      dat1 = dat1 / 10;
      ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height = dat1;
    }
    else if (strstr(p, "MODE_FUMIGATE_NORMAL"))
    {
      MosFumigateNormalFunction();

      dat1 = skip_atoi(strstr(p, "MODE_FUMIGATE_NORMAL/") + strlen("MODE_FUMIGATE_NORMAL/"));
      dat2 = skip_atoi(strstr(p, "MODE_FUMIGATE_NORMAL/") + strlen("MODE_FUMIGATE_NORMAL/___"));
      dat1 = dat1 * 10 + dat2;
      dat1 = dat1 / 10;
      ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height = dat1;
    }
    if (strstr(p, "FUMIGATE_AUTO_M2"))
    {
      Set_Fumigate_Area5_15m2();
    }
    else if (strstr(p, "FUMIGATE_0_15_M2"))
    {
      Set_Fumigate_Area5_15m2();
    }
    else if (strstr(p, "FUMIGATE_15_30_M2"))
    {
      Set_Fumigate_Area15_30m2();
    }
    else if (strstr(p, "FUMIGATE_30_50_M2"))
    {
      Set_Fumigate_Area30_50m2();
    }
    else if (strstr(p, "FUMIGATE_50_80_M2"))
    {
      Set_Fumigate_Area50_80m2();
    }
    else if (strstr(p, "FUMIGATE_80_100_M2"))
    {
      Set_Fumigate_Area80_100m2();
    }
    else if (strstr(p, "FUMIGATE_100_150_M2"))
    {
      Set_Fumigate_Area100_150m2();
    }
    else if (strstr(p, "FUMIGATE_150_200_M2"))
    {
      Set_Fumigate_Area150_200m2();
    }

    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
}

/**
  * @brief  设置驱蚊设置
  * @param  p:指向接收到的字符串
  * @retval 无
  */
static void MQTT_Repel_sett_set(const char *p)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    if (strstr(p, "MODE_REPEL_AIR"))
    {
      AirConditionerFunction(); //这里不用更改模式,但如果涉及到开启或者关闭就得切换到相应的模式
    }
    else if (strstr(p, "MODE_REPEL_MATERNAL"))
    {
      MaternalFunction();
    }
    else if (strstr(p, "MODE_REPEL_ENCHANCE"))
    {
      MosRepelEnchanceFunction();
    }
    if (strstr(p, "REPEL_AUTO_M2"))
    {
      Set_Repel_Area0_10m2();
    }
    else if (strstr(p, "REPEL_BENEATH_10M2"))
    {
      Set_Repel_Area0_10m2();
    }
    else if (strstr(p, "REPEL_10_20_M2"))
    {
      Set_Repel_Area10_20m2();
    }
    else if (strstr(p, "REPEL_21_30_M2")) //上面的只能4选一
    {
      Set_Repel_Area21_30m2();
    }

    if (strstr(p, "REPEL_TIMING_"))
    { //这里是关于时间的设置
      uint8_t dat1 = 0;
      uint8_t dat2 = 0;

      if (strstr(p, "REPEL_TIMING_NORMAL"))
      { //这里是正常驱蚊
        RepelNormalSettFunction();
      }
      else
      { //这里定时驱蚊,这里还得提取时间段,然后还要看是否是每天
        if (strstr(p, "REPEL_REPEAT"))
        {
          RepelTimeRepeat();
        }
        else if (strstr(p, "REPEL_ONCE"))
        {
          RepelTimeNotRepeat();
        } //这里只能二选一

        if (strstr(p, "REPEL_TIMING_")) //这里还得提取时间段
        {
          dat1 = skip_atoi(strstr(p, "REPEL_TIMING_") + strlen("REPEL_TIMING_"));     //开始时间
          dat2 = skip_atoi(strstr(p, "REPEL_TIMING_") + strlen("REPEL_TIMING_") + 3); //结束时间
          ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour = dat1;
          ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour = dat2;
          RepelTimingSett(); //这个函数中有存储功能
        }
      }
    }

    if (strstr(p, "BACKLIGHT_")) //这里就是背光   010
    {                            //无论是手动背光还是自动背光
      if (strstr(p, "BACKLIGHT_AUTO"))
      {                  //这里是自动背光
        AutoBacklight(); //这里面已经进行了存储
      }
      else if (strstr(p, "BACKLIGHT_MANUAL"))
      {                    //这里是自定义驱蚊
        ManualBacklight(); //这里面已经进行了存储
      }                    //上面是二选一

      if (strstr(p, "BACKLIGHT_VALUE_"))
      {
        uint8_t dat1 = 0;
        dat1 = skip_atoi(strstr(p, "BACKLIGHT_VALUE_") + strlen("BACKLIGHT_VALUE_")); //背光值
        dat1 = dat1 / 10;
        if (dat1 >= 8)
        {
          dat1 = 8;
        }
        ConfigParam.RepelSetting.repel_sett_data.backlight = dat1;
        write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
      }
    }

    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
}

/**
  * @brief  转换为相应的香薰模式
  * @param  p:指向接收到的字符串
  * @retval 无
  */
static void MQTT_Aroma_sett_set(const char *p)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    MosAromaFunction();

    if (strstr(p, "AROMA_AUTO_M2"))
    {
      Set_Repel_Area0_10m2();
    }
    else if (strstr(p, "AROMA_BENEATH_10M2"))
    {
      Set_Repel_Area0_10m2();
    }
    else if (strstr(p, "AROMA_10_20_M2"))
    {
      Set_Repel_Area10_20m2();
    }
    else if (strstr(p, "AROMA_21_30_M2")) //上面的只能4选一
    {
      Set_Repel_Area21_30m2();
    }

    if (strstr(p, "AROMA_TIMING_"))
    { //这里是关于时间的设置
      uint8_t dat1 = 0;
      uint8_t dat2 = 0;

      if (strstr(p, "AROMA_TIMING_NORMAL"))
      { //这里是正常驱蚊
        RepelNormalSettFunction();
      }
      else
      { //这里定时驱蚊,这里还得提取时间段,然后还要看是否是每天
        if (strstr(p, "AROMA_REPEAT"))
        {
          RepelTimeRepeat();
        }
        else if (strstr(p, "AROMA_ONCE"))
        {
          RepelTimeNotRepeat();
        } //这里只能二选一

        if (strstr(p, "AROMA_TIMING_")) //这里还得提取时间段
        {
          dat1 = skip_atoi(strstr(p, "AROMA_TIMING_") + strlen("AROMA_TIMING_"));     //开始时间
          dat2 = skip_atoi(strstr(p, "AROMA_TIMING_") + strlen("AROMA_TIMING_") + 3); //结束时间
          ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour = dat1;
          ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour = dat2;
          RepelTimingSett(); //这个函数中有存储功能
        }
      }
    }

    if (strstr(p, "BACKLIGHT_")) //这里就是背光   010
    {                            //无论是手动背光还是自动背光
      if (strstr(p, "BACKLIGHT_AUTO"))
      {                  //这里是自动背光
        AutoBacklight(); //这里面已经进行了存储
      }
      else if (strstr(p, "BACKLIGHT_MANUAL"))
      {                    //这里是自定义驱蚊
        ManualBacklight(); //这里面已经进行了存储
      }                    //上面是二选一

      if (strstr(p, "BACKLIGHT_VALUE_"))
      {
        uint8_t dat1 = 0;
        dat1 = skip_atoi(strstr(p, "BACKLIGHT_VALUE_") + strlen("BACKLIGHT_VALUE_")); //背光值
        dat1 = dat1 / 10;
        if (dat1 >= 8)
        {
          dat1 = 8;
        }
        ConfigParam.RepelSetting.repel_sett_data.backlight = dat1;
        write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
      }
    }

    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
}

/**
  * @brief  转换为相应的灭蚊模式,并开始工作
  * @param  无
  * @retval 无
  */
static void FumigateOn(void)
{
  switch (ConfigParam.WorkingMode.work_mode_data.fumigate_buf_mode)
  {
  case ENUM_FUMIGATE_NORMAL_MODE:
    MosFumigateNormalFunction();
    break;
  case ENUM_FUMIGATE_ENCHANCE_MODE:
    MosFumigateEnchanceFunction();
    break;
  default:
    MosFumigateNormalFunction();
    break;
  }
  SwitchOn();
}

/**
  * @brief  转换为相应的驱蚊模式,并开始工作
  * @param  无
  * @retval 无
  */
static void RepelOn(void)
{
  switch (ConfigParam.WorkingMode.work_mode_data.repel_buf_mode)
  {
  case ENUM_REPEL_AIR_CONDI_MODE:
    AirConditionerFunction();
    break;
  case ENUM_REPEL_MATERNAL_MODE:
    MaternalFunction();
    break;
  case ENUM_REPEL_ENCHANCE_MODE:
    MosRepelEnchanceFunction();
    break;
  default:
    MosRepelEnchanceFunction();
    break; //默认是正常驱蚊模式
  }
  SwitchOn();
}

/**
  * @brief  转换为香薰模式,并开始工作
  * @param  无
  * @retval 无
  */
static void AromaOn(void)
{
  MosAromaFunction(); //将当前工作模式改为香薰
  SwitchOn();
}

// 愿中国青年都摆脱冷气，只是向上走，不必听自暴自弃者流的话。能做事的做事，能发声的发声。
// 有一分热，发一分光，就令萤火一般，也可以在黑暗里发一点光，不必等候炬火。
// 此后如竟没有炬火：我便是唯一的光。倘若有了炬火，出了太阳，我们自然心悦诚服的消失，不但毫无不平，
// 而且还要随喜赞美这炬火或太阳；因为他照了人类，连我都在内

/**
 *  @brief mqtt接受动作函数       当接受到来自服务器的MQTT消息时,便会启动该线程
 *  @param param :void 类型的指针
 *  @brief 无  
 */
static void mqtt_rev_action(void)
{
  char buf[128];

  xSemaphoreTake(mqtt_rev_sem, portMAX_DELAY);

  IsChangeMenu = true;
  printf("The size of available heap [%d] ... \n", esp_get_free_heap_size());
  memset(buf, 0, sizeof(buf));   //这个还是有必要的
  Process(mqtt_rev_buffer, buf); //已经将字符串copy到了buf中   注意这里是value中的值
  printf("value :%s\n", buf);
  if (strstr(buf, "READ_STATE_CMD"))
  { //读取当前灭蚊器的工作状态
    //在tx线程中发送当前前灭蚊器的状态(灭蚊开始,灭蚊结束.....)
    mqtt_pub_queue_enum = MQTT_SEND_STATE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "RTC_20"))
  {
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "RTC_20"), sizeof(cmd_buf)); //设置灭蚊器的RTC
    MQTT_RTC_Set(strstr(buf, "RTC_20") + strlen("RTC_20"));   //YY/MM_DD/HH_MM_SS这个才是传进去的东东
  }
  else if (strstr(buf, "READ_LANGUAGE"))
  { //读取当前是什么语言
    mqtt_pub_queue_enum = MQTT_SEND_LANGUAGE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_LANGUAGE"))
  { //读取当前是什么语言
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_LANGUAGE"), sizeof(cmd_buf));
    MQTT_Language_Set(strstr(buf, "SET_LANGUAGE") + strlen("SET_LANGUAGE_"));
  }
  else if (strstr(buf, "READ_REPEL_FACTORY_SETT"))
  { //读取驱蚊出厂设置
    mqtt_pub_queue_enum = MQTT_SEND_REPEL_FACTORY_SETT;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_REPEL_FACTORY_SETT/"))
  { //设置驱蚊出厂设置参数
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_REPEL_FACTORY_SETT/"), sizeof(cmd_buf));
    MQTT_Repel_factory_sett_set(strstr(buf, "SET_REPEL_FACTORY_SETT/") + strlen("SET_REPEL_FACTORY_SETT/"));
  }
  else if (strstr(buf, "READ_FUMIGATE_FACTORY_SETT"))
  { //读取灭蚊出厂设置
    mqtt_pub_queue_enum = MQTT_SEND_FUMIGATE_FACTORY_SETT;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_FUMIGATE_FACTORY_SETT/"))
  { //设置灭蚊出厂设置参数
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_FUMIGATE_FACTORY_SETT/"), sizeof(cmd_buf));
    MQTT_Fumigate_factory_sett_set(strstr(buf, "SET_FUMIGATE_FACTORY_SETT/") + strlen("SET_FUMIGATE_FACTORY_SETT/"));
  }
  else if (strstr(buf, "READ_PUMP_NUM"))
  { //设置灭蚊出厂设置参数
    mqtt_pub_queue_enum = MQTT_SEND_PUMP_NUM;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "READ_FUMIGATE_SETT"))
  { //读取当前灭蚊设置
    mqtt_pub_queue_enum = MQTT_SEND_FUMIGATE_SETT;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_FUMIGATE_START"))
  { //灭蚊开始    //这里还得有一个状态切换,切换成灭蚊状态
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_FUMIGATE_START"), sizeof(cmd_buf));
    FumigateOn();
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_FUMIGATE_STOP"))
  { //灭蚊停止    //这里还得有一个状态切换,切换成灭蚊状态
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_FUMIGATE_STOP"), sizeof(cmd_buf));
    SwitchOff();
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_FUMIGATE_SETT/"))
  { //对灭蚊设置进行设置
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_FUMIGATE_SETT/"), sizeof(cmd_buf));
    MQTT_Fumigate_sett_set(strstr(buf, "SET_FUMIGATE_SETT/") + strlen("SET_FUMIGATE_SETT/"));
  }
  else if (strstr(buf, "READ_REPEL_TIME"))
  { //读取当前已驱蚊时间
    mqtt_pub_queue_enum = MQTT_SEND_REPEL_TIME;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_REPEL_STOP"))
  { //停止灭蚊
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_REPEL_STOP"), sizeof(cmd_buf));
    SwitchOff(); //这里还得进行模式的切换
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_REPEL_START"))
  { //停止开始
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_REPEL_START"), sizeof(cmd_buf));
    RepelOn(); //这里还得进行模式的切换
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "REPEL_MEDICINE_RESET"))
  { //驱蚊药量重置
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "REPEL_MEDICINE_RESET"), sizeof(cmd_buf));
    RefillRepelMedicine();
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "AROMA_MEDICINE_RESET"))
  { //驱蚊药量重置
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "AROMA_MEDICINE_RESET"), sizeof(cmd_buf));
    RefillRepelMedicine();
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "READ_REPEL_SETT"))
  { //读取驱蚊设置
    mqtt_pub_queue_enum = MQTT_SEND_REPEL_SETT;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_REPEL_SETT/"))
  { //对驱蚊设置进行设置
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_REPEL_SETT/"), sizeof(cmd_buf));
    MQTT_Repel_sett_set(strstr(buf, "SET_REPEL_SETT/") + strlen("SET_REPEL_SETT/"));
  }
  else if (strstr(buf, "SET_AROMA_STOP"))
  { //停止灭蚊
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_AROMA_STOP"), sizeof(cmd_buf));
    SwitchOff(); //这里还得进行模式的切换
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_AROMA_START"))
  { //停止开始
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_AROMA_START"), sizeof(cmd_buf));
    AromaOn(); //这里还得进行模式的切换
    mqtt_pub_queue_enum = MQTT_SEND_TRUE;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "READ_AROMA_SETT"))
  { //读取香薰设置
    mqtt_pub_queue_enum = MQTT_SEND_AROMA_SETT;
    pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
    if (mqtt_is_connected == MQTT_CONNECTED)
    {
      xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    }
  }
  else if (strstr(buf, "SET_AROMA_SETT/"))
  { //对香薰设置进行设置
    memset(cmd_buf, 0x00, sizeof(cmd_buf));
    strncpy(cmd_buf, strstr(buf, "SET_AROMA_SETT/"), sizeof(cmd_buf));
    MQTT_Aroma_sett_set(strstr(buf, "SET_AROMA_SETT/") + strlen("SET_AROMA_SETT/"));
  }
}

/**
 *  @brief mqtt接受线程
 *  @param param :void 类型的指针
 *  @brief 无  
 */
void MQTT_REV_Driver_Task(void *parm)
{
  cJSON_Data = cJSON_Data_Init();
  //这里可以放cJSON初始化
  while (1)
  {
    mqtt_rev_action();
  }
}

/**************************************上面是MQTT接收处理函数********************************************/

/**************************************下面是MQTT发送处理函数********************************************/

/**
 *  @brief 将要发送的字符串封装成JSON格式,并发布MQTT消息   所有的发送函数都得调用这个函数
 *  @param p :指向待转化成JSON中value键值对中值的字符串   超级价值,领先好几代
 *  @brief 无  
 */
static void cmd_pub_process(const char *ptr)
{ //上面是表示指向的变量内容不可改
  uint8_t res = 0;

  res = cJSON_Update(cJSON_Data, VALUE_KEY, (void *)ptr);
  if (res == 1)
  { //更新成功
    char *p = cJSON_Print(cJSON_Data);
    printf("TX:%s\n", p);
    //发布消息
    esp_mqtt_client_publish(mqtt_client, ConfigParam.MQTT_Param.mqtt_param_data.mqtt_topic, p, 0, 2, 0); //MQTT发布和接受处理还是单独做两个函数吧
    free(p);
    p = NULL;
  }
}

// /**
//  *  @brief 将APP发过来的指令原路返回 这个函数主要是针对非read而言的,就是针对set类型的函数而言的
//  *  @param 无
//  *  @brief 无
//  */
// static void mqtt_true_send(void)
// {
//   cmd_pub_process(cmd_buf);
// }
/**
  * @brief  向APP发送当前是什么语言
  * @param  无
  * @retval 无
  */
static void MQTT_Language_send(void)
{
  cmd_pub_process("LANGUAGE_SIMPLIFIED");
}

/**
  * @brief  向APP发送当前是什么状态   那个定时驱蚊得改一改
  * @param  无
  * @retval 无
  */
static void MQTT_State_send(void)
{
  switch (ConfigParam.WorkingMode.work_mode_data.working_mode)
  {
  case ENUM_FUMIGATE_NORMAL_MODE:
  case ENUM_FUMIGATE_ENCHANCE_MODE:
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      cmd_pub_process("SET_FUMIGATE_STOP");
    }
    else
    {
      cmd_pub_process("SET_FUMIGATE_START");
    }
    break;
  case ENUM_REPEL_AIR_CONDI_MODE:
  case ENUM_REPEL_MATERNAL_MODE:
  case ENUM_REPEL_ENCHANCE_MODE:
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      cmd_pub_process("SET_REPEL_STOP");
    }
    else
    {
      cmd_pub_process("SET_REPEL_START");
    }
    break;
  case ENUM_AROMA_MODE:
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      cmd_pub_process("SET_AROMA_STOP");
    }
    else
    {
      cmd_pub_process("SET_AROMA_START");
    }
    break;
  default:
    break;
  }
}

/**
  * @brief  向APP发送驱蚊出厂设置中参数
  * @param  无
  * @retval 无
  */
static void MQTT_Repel_Factory_setting_send(void)
{
  char buf[100];

  sprintf(buf, "REPEL_FACTORY_SETT/%03d/%03d_%03d/%03d_%03d/%03d_%03d/%03d_%03d_%03d/%04d",
          ConfigParam.FactorySetting.factory_sett_data.InitRepelTime,
          ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time, ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time,
          ConfigParam.FactorySetting.factory_sett_data.maternal_open_time, ConfigParam.FactorySetting.factory_sett_data.maternal_close_time,
          ConfigParam.FactorySetting.factory_sett_data.normal_open_time, ConfigParam.FactorySetting.factory_sett_data.normal_close_time,
          ConfigParam.FactorySetting.factory_sett_data.area10m2_factory, ConfigParam.FactorySetting.factory_sett_data.area20m2_factory, ConfigParam.FactorySetting.factory_sett_data.area30m2_factory,
          100);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送灭蚊出厂设置中的参数
  * @param  无
  * @retval 无
  */
static void MQTT_Fumigate_Factory_setting_send(void)
{
  char buf[64];

  sprintf(buf, "FUMIGATE_FACTORY_SETT/%03d/%03d_%03d/%04.1f/%03d",
          ConfigParam.FactorySetting.factory_sett_data.evacuation_times,
          (uint16_t)ConfigParam.PID_Param.pid_param_data.SetPoint, (uint16_t)CurrentTemp,
          ConfigParam.FactorySetting.factory_sett_data.timers_per10m3,
          ConfigParam.FactorySetting.factory_sett_data.fumigate_time);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送当前已经泵了多少次
  * @param  无
  * @retval 无
  */
static void MQTT_Pump_num_send(void)
{
  char buf[64];

  sprintf(buf, "PUMP_%03d", ConfigParam.PumpCnt.pump_cnt_data.pumpcnt);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送离子浓度和当前是否在线
  * @param  无
  * @retval 无
  */
static void MQTT_Ion_concentration_send(void)
{
  char buf[64];

  sprintf(buf, "ONLINE/ION_CONCEN_%04d", 666);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送当前的灭蚊设置   看来有些地方还得改！！
  * @param  无
  * @retval 无
  */
static void MQTT_Fumigate_setting_send(void)
{
  char buf[128];
  const char *buff1;
  const char *buff2;
  const char *buff3;
  const char *buff4;

  switch (ConfigParam.WorkingMode.work_mode_data.fumigate_buf_mode)
  {
  case ENUM_FUMIGATE_ENCHANCE_MODE:
    buff1 = "MODE_FUMIGATE_ENCHANCE";
    break;
  case ENUM_FUMIGATE_NORMAL_MODE:
    buff1 = "MODE_FUMIGATE_NORMAL";
    break;
  default:
    buff1 = "MODE_FUMIGATE_NORMAL";
    break;
  }
  MedicineBottleResistor(); //先从事相关工作,吸取经验
  switch (ConfigParam.PumpCnt.pump_cnt_data.type)
  {
  case NORMAL_MEDICINE:
    buff2 = "NORMAL_MEDICINE";
    break;
  case MEDIAN_MEDICINE:
    buff2 = "MEDIUM_MEDICINE";
    break;
  case ENCHANCE_MEDICINE:
    buff2 = "ENCHANCE_MEDICINE";
    break;
  default:
    buff2 = "NORMAL_MEDICINE";
    break;
  }
  switch (ConfigParam.FumigateSetting.fumi_sett_data.fumi_sett_area)
  {
  case ENUM_0_15_M2_F:
    buff3 = "FUMIGATE_0_15_M2";
    break;
  case ENUM_15_30_M2_F:
    buff3 = "FUMIGATE_15_30_M2";
    break;
  case ENUM_30_50_M2_F:
    buff3 = "FUMIGATE_30_50_M2";
    break;
  case ENUM_50_80_M2_F:
    buff3 = "FUMIGATE_50_80_M2";
    break;
  case ENUM_80_100_M2_F:
    buff3 = "FUMIGATE_80_100_M2";
    break;
  case ENUM_100_150_M2_F:
    buff3 = "FUMIGATE_100_150_M2";
    break;
  case ENUM_150_200_M2_F:
    buff3 = "FUMIGATE_150_200_M2";
    break;
  default:
    buff3 = "FUMIGATE_0_15_M2";
    break;
  }

  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_FUMIGATE_NORMAL_MODE || ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_FUMIGATE_ENCHANCE_MODE)
  {
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    { //处于开始工作状态
      buff4 = "SET_FUMIGATE_STOP";
    }
    else
    {
      buff4 = "SET_FUMIGATE_START";
    }
  }
  else
  { //当不处于灭蚊状态时,那么灭蚊就应该停止
    buff4 = "SET_FUMIGATE_STOP";
  }

  sprintf(buf, "FUMIGATE_SETT/%03d/%s/%04.1f/%s/%s/ION_CONCEN_%04d/REMAINS_%03d_%03d/%s",
          ConfigParam.FactorySetting.factory_sett_data.fumigate_time,
          buff1,
          ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height,
          buff2,
          buff3,
          666,
          percentage_of_repel_medicine,
          percentage_of_fumigate_medicine,
          buff4);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送当前已香薰用时
  * @param  无
  * @retval 无
  */
static void MQTT_Aroma_time_send(void)
{
  char buf[64];

  sprintf(buf, "AROMA_TIME_%04d", repel_cnt);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送当前已驱蚊用时
  * @param  无
  * @retval 无
  */
static void MQTT_Repel_time_send(void)
{
  char buf[64];

  sprintf(buf, "REPEL_TIME_%04d", repel_cnt);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送当前剩余药量
  * @param  无
  * @retval 无
  */
static void MQTT_Remains_send(void)
{
  char buf[64];

  sprintf(buf, "REMAINS_%03d_%03d", percentage_of_repel_medicine, percentage_of_fumigate_medicine);
  cmd_pub_process(buf);
}

/**
  * @brief  向APP发送当前的驱蚊设置
  * @param  无
  * @retval 无
  */
static void MQTT_Send_repel_sett(void)
{
  char buf[256];
  const char *buff1;
  const char *buff2;
  const char *buff3;
  const char *buff4;
  char buf1[40];
  char buf3[30];

  switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
  {
  case ENUM_BENEATH_10M2:
    buff1 = "REPEL_BENEATH_10M2";
    break;
  case ENUM_10_20_M2:
    buff1 = "REPEL_10_20_M2";
    break;
  case ENUM_21_30_M2:
    buff1 = "REPEL_21_30_M2";
    break;
  default:
    buff1 = "REPEL_BENEATH_10M2";
    break;
  }
  switch (ConfigParam.WorkingMode.work_mode_data.repel_buf_mode)
  {
  case ENUM_REPEL_AIR_CONDI_MODE:
    buff2 = "MODE_REPEL_AIR";
    break;
  case ENUM_REPEL_MATERNAL_MODE:
    buff2 = "MODE_REPEL_MATERNAL";
    break;
  case ENUM_REPEL_ENCHANCE_MODE:
    buff2 = "MODE_REPEL_ENCHANCE";
    break;
  default:
    buff2 = "MODE_REPEL_ENCHANCE";
    break; //默认是增强驱蚊模式
  }
  switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode)
  { //
  case ENUM_MOS_REPEL_NORMAL:
    sprintf(buf1, "%s", "REPEL_TIMING_NORMAL");
    break;
  case ENUM_MOS_REPEL_TIMING:
    sprintf(buf1, "REPEL_TIMING_%02d_%02d/%s", ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour,
            ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour,
            ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat ? "REPEL_REPEAT" : "REPEL_ONCE");
    break;
  default:
    sprintf(buf1, "%s", "REPEL_TIMING_NORMAL");
    break;
  }
  { //这里表示背光为手动背光
    buff3 = "BACKLIGHT_MANUAL";
  }

  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_AIR_CONDI_MODE ||
      ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_MATERNAL_MODE ||
      ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_ENCHANCE_MODE)
  {
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      buff4 = "SET_REPEL_STOP";
    }
    else
    {
      buff4 = "SET_REPEL_START";
    }
  }
  else
  { //当不处于驱蚊状态时,那么驱蚊就应该停止
    buff4 = "SET_REPEL_STOP";
  }
  sprintf(buf3, "BACKLIGHT_VALUE_%03d", ConfigParam.RepelSetting.repel_sett_data.backlight * 10);
  sprintf(buf, "REPEL_SETT/%s/%s/%s/%s/%s/REPEL_TIME_%04d/ION_CONCEN_%04d/REMAINS_%03d_%03d/%s",
          buff1,
          buff2,
          buf1,
          buff3,
          buf3,
          repel_cnt,
          666,
          percentage_of_repel_medicine,
          percentage_of_fumigate_medicine,
          buff4);

  cmd_pub_process(buf);
}

/**
  * @brief  根据相关参数,重新配置ESP8266
  * @param  无  
  * @retval 无
  */
void MQTT_Send_aroma_sett(void)
{
  char buf[256];
  const char *buff1;
  const char *buff3;
  const char *buff4;
  char buf1[40];
  char buf3[30];

  switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
  {
  case ENUM_BENEATH_10M2:
    buff1 = "AROMA_BENEATH_10M2";
    break;
  case ENUM_10_20_M2:
    buff1 = "AROMA_10_20_M2";
    break;
  case ENUM_21_30_M2:
    buff1 = "AROMA_21_30_M2";
    break;
  default:
    buff1 = "AROMA_BENEATH_10M2";
    break;
  }
  switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode)
  { //
  case ENUM_MOS_REPEL_NORMAL:
    sprintf(buf1, "%s", "AROMA_TIMING_NORMAL");
    break;
  case ENUM_MOS_REPEL_TIMING:
    sprintf(buf1, "AROMA_TIMING_%02d_%02d/%s", ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour,
            ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour,
            ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat ? "AROMA_REPEAT" : "AROMA_ONCE");
    break;
  default:
    sprintf(buf1, "%s", "AROMA_TIMING_NORMAL");
    break;
  }

  { //这里表示背光为手动背光
    buff3 = "BACKLIGHT_MANUAL";
  }

  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_AROMA_MODE)
  {
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      buff4 = "SET_AROMA_STOP";
    }
    else
    {
      buff4 = "SET_AROMA_START";
    }
  }
  else
  { //当不处于香薰状态时,那么香薰就应该停止
    buff4 = "SET_AROMA_STOP";
  }

  sprintf(buf3, "BACKLIGHT_VALUE_%03d", ConfigParam.RepelSetting.repel_sett_data.backlight * 10);
  sprintf(buf, "AROMA_SETT/%s/%s/%s/%s/AROMA_TIME_%04d/ION_CONCEN_%04d/REMAINS_%03d_%03d/%s",
          buff1,
          buf1,
          buff3,
          buf3,
          repel_cnt,
          666,
          percentage_of_repel_medicine,
          percentage_of_fumigate_medicine,
          buff4);

  cmd_pub_process(buf);
}

/**
  * @brief  通知APP当前药瓶没有安装好
  * @param  无  
  * @retval 无
  */
void MQTT_Send_bottle_uninstall(void)
{
  cmd_pub_process("BOTTLE_UNINSTALL");
}

/**
  * @brief  通知APP当前没灭蚊药了
  * @param  无  
  * @retval 无
  */
void MQTT_Send_No_Fumigate_Medicine(void)
{
  cmd_pub_process("NO_FUMIGATE_MEDICINE");
}

/**
  * @brief  通知APP当前没驱蚊药了
  * @param  无  
  * @retval 无
  */
void MQTT_Send_No_Repel_Medicine(void)
{
  cmd_pub_process("NO_REPEL_MEDICINE");
}

/**
 *  @brief mqtt发送线程
 *  @param param :void 类型的指针
 *  @brief 无  
 */
void MQTT_PUB_Driver_Task(void *parm)
{
  //这里可以放cJSON初始化
  while (1)
  { //mqtt发送函数,得使用MessageQueue
    xQueueReceive(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
    switch (*pMQTT_PUB_QUEUE_ENUM)
    {
    case MQTT_SEND_STATE:
      MQTT_State_send();
      vTaskDelay(4000 / portTICK_PERIOD_MS); //连发三次,每隔4s一次
      MQTT_State_send();
      break;
    case MQTT_SEND_TRUE:
      cmd_pub_process(cmd_buf); //这里应该原路返回指令
      break;
    case MQTT_SEND_LANGUAGE:
      MQTT_Language_send();
      break;
    case MQTT_SEND_REPEL_FACTORY_SETT:
      MQTT_Repel_Factory_setting_send(); //下面得注意RAM的使用
      break;
    case MQTT_SEND_FUMIGATE_FACTORY_SETT:
      MQTT_Fumigate_Factory_setting_send();
      break;
    case MQTT_SEND_PUMP_NUM:
      MQTT_Pump_num_send();
      break;
    case MQTT_SEND_ION_CONCENTRATION:
      MQTT_Ion_concentration_send();
      vTaskDelay(4000 / portTICK_PERIOD_MS); //连发三次,每隔4s一次
      MQTT_Ion_concentration_send();
      break;
    case MQTT_SEND_FUMIGATE_SETT: //
      MQTT_Fumigate_setting_send();
      break;
    case MQTT_SEND_REPEL_TIME: //  SEND_AROMA_TIME
      MQTT_Repel_time_send();
      break;
    case MQTT_SEND_AROMA_TIME: //
      MQTT_Aroma_time_send();
      break;
    case MQTT_SEND_REMAINS: //
      MQTT_Remains_send();
      vTaskDelay(4000 / portTICK_PERIOD_MS); //连发三次,每隔4s一次
      MQTT_Remains_send();
      break;
    case MQTT_SEND_REPEL_SETT: //
      MQTT_Send_repel_sett();
      break;
    case MQTT_SEND_AROMA_SETT:
      MQTT_Send_aroma_sett();
      break;
    case MQTT_SEND_BOTTLE_UNINSTALL:
      MQTT_Send_bottle_uninstall();
      vTaskDelay(4000 / portTICK_PERIOD_MS); //连发三次,每隔4s一次
      MQTT_Send_bottle_uninstall();
      break;
    default:
      break;
    }
  }
}
/******************************************************************************************************************************/
